package com.training.web.controller.comtent;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.training.common.annotation.Log;
import com.training.common.core.controller.BaseController;
import com.training.common.core.domain.AjaxResult;
import com.training.common.enums.BusinessType;
import com.training.content.domain.TrainInfo;
import com.training.content.service.ITrainInfoService;
import com.training.common.utils.poi.ExcelUtil;
import com.training.common.core.page.TableDataInfo;

/**
 * 培训计划Controller
 * 
 * @author training
 * @date 2021-10-25
 */
@RestController
@RequestMapping("/train/info")
public class TrainInfoController extends BaseController
{
    @Autowired
    private ITrainInfoService trainInfoService;

    /**
     * 查询培训计划列表
     */
    @PreAuthorize("@ss.hasPermi('train:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainInfo trainInfo)
    {
        startPage();
        List<TrainInfo> list = trainInfoService.selectTrainInfoList(trainInfo);
        return getDataTable(list);
    }

    /**
     * 导出培训计划列表
     */
    @PreAuthorize("@ss.hasPermi('train:info:export')")
    @Log(title = "培训计划", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TrainInfo trainInfo)
    {
        List<TrainInfo> list = trainInfoService.selectTrainInfoList(trainInfo);
        ExcelUtil<TrainInfo> util = new ExcelUtil<TrainInfo>(TrainInfo.class);
        return util.exportExcel(list, "培训计划数据");
    }

    /**
     * 获取培训计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('train:info:query')")
    @GetMapping(value = "/{trainId}")
    public AjaxResult getInfo(@PathVariable("trainId") Long trainId)
    {
        return AjaxResult.success(trainInfoService.selectTrainInfoByTrainId(trainId));
    }

    /**
     * 新增培训计划
     */
    @PreAuthorize("@ss.hasPermi('train:info:add')")
    @Log(title = "培训计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainInfo trainInfo)
    {
        return toAjax(trainInfoService.insertTrainInfo(trainInfo));
    }

    /**
     * 修改培训计划
     */
    @PreAuthorize("@ss.hasPermi('train:info:edit')")
    @Log(title = "培训计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainInfo trainInfo)
    {
        return toAjax(trainInfoService.updateTrainInfo(trainInfo));
    }

    /**
     * 删除培训计划
     */
    @PreAuthorize("@ss.hasPermi('train:info:remove')")
    @Log(title = "培训计划", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trainIds}")
    public AjaxResult remove(@PathVariable Long[] trainIds)
    {
        return toAjax(trainInfoService.deleteTrainInfoByTrainIds(trainIds));
    }
}
